package com.ycw.servlet.xiaocai;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.ycw.dao.TenantDao;
import com.ycw.dao.impl.TenantDaoImpl;

/**
 * Servlet implementation class tenantDeleteByIdServlet
 */
@WebServlet("/tenantDeleteByIdServlet")
public class tenantDeleteByIdServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public tenantDeleteByIdServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		TenantDao td = new TenantDaoImpl();
		String id = request.getParameter("t_id");
		int t_id = Integer.parseInt(id);
		boolean f = td.tenantDeleteById(t_id);
		/*
		 * if(f) { System.out.println("删除成功"); }else {
		 * System.out.println("删除失败"); }
		 */
		// 向前端发送JSON数据
		String resJSON = JSON.toJSONString(f);
		PrintWriter out = response.getWriter();
		out.write(resJSON);
		out.close();
	}

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
	}

	@Override
	public void init() throws ServletException {
		// TODO Auto-generated method stub
		super.init();
	}

}
